
package controllers.classes;

import classes.Breadcrumbs;
import classes.HibernateUtil;
import dao.QuizDao;
import dao.QuizQuestionsDao;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import models.Quiz;
import dao.CourseDao;
import models.Quizquestion;
import models.Course;

/**
 * This servlet handles the view quiz and sets a quizlist.
 * @author Vuong Pham<Vuong.Pham@hva.nl>
 */
public class ViewQuizController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            long id = Long.parseLong(request.getParameter("course"));
            HibernateUtil hu = new HibernateUtil();
            QuizDao qd = new QuizDao(hu.openSession());
            List<Quiz> quizList = qd.findAllbyCourse(id);
            
            CourseDao cd = new CourseDao(hu.openSession());
            Course course = cd.get(id);
             
            request.setAttribute("quizList", quizList);
            
            hu.close();
            
            // Breadcrumbs
            Breadcrumbs[] breadcrumbs = {
                new Breadcrumbs("Index", "Home"),
                new Breadcrumbs("Category", "Course catalog"),
                new Breadcrumbs("Course?courseid=" + course.getId(), course.getName()),
                new Breadcrumbs("ViewQuiz?course=" + course.getId(), "Quizzes")
            };
            request.setAttribute("breadcrumbs", breadcrumbs);
            
            RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/view_quizzes.jsp");
            dispatcher.forward(request, response);
    }

}
